/*
 * CS_SOCIAL_CONFIRM_NEWS_V2.cpp
 *
 *  Created on: 2014. 4. 21.
 *      Author: mega
 */

#include "../../User.h"
#include "../../Command.h"
#include "../../Proxy.h"
#include "../../NResource/Static.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_SOCIAL_CONFIRM_NEWS_V2(User * pUser, ::Network::Packet * pPacket)
{
/*	// 소식 확인.
	CS_SOCIAL_CONFIRM_NEWS_V2			0x216A
	{
		u8 u8confirm_type;				// 0 : 한개 2 : 하트(우정포인트)가 포함된 뉴스들 확인 (REF. friend_news_confirm_type)
		u64 u64news_seq;				// NEWS id ( u8confirm_type == 1,2일때 0으로)
		u32 u32gid;						// 상대방 GID ( u8confirm_type == 1,2일때 0으로)
	}

	SC_SOCIAL_CONFIRM_NEWS_V2			0x216B
	{
		s16 s16ack;
		u32 u32heart_count;
		u32 u32stamina_count;
		u64 u64news_seq;				// 보낸 NEWS id
	}*/

	PREPARE_PACKET;

	ConfirmNewsV2Syn syn;

	uint8_t confirm_type = 0;

	*pPacket >> confirm_type >> syn.news_seq >> syn.news_type >> syn.gid;

	syn.confirm_type = confirm_type;

	if (syn.confirm_type != 0 && syn.confirm_type != 2)
	{
		DEBUGLOG("%s : INVALID confirm_type=%d", __FUNCTION__, confirm_type);

		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		*pAck << static_cast<int16_t>(ACK_UNKNOWN_ERROR);
		pAck->MakePacket(CMD_SC_SOCIAL_CONFIRM_NEWS_V2);
		pUser->Send(pAck);

		return;
	}

	// 한개만 받기
	if (syn.confirm_type == 0)
	{
		if (syn.news_seq <= 0 || syn.gid <= 0)
		{
			DEBUGLOG("%s : INVALID news_seq=%d, gid=%d", __FUNCTION__, syn.news_seq, syn.gid);

			::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
			*pAck << static_cast<int16_t>(ACK_UNKNOWN_ERROR);
			pAck->MakePacket(CMD_SC_SOCIAL_CONFIRM_NEWS_V2);
			pUser->Send(pAck);

			return;
		}
	}

	NResource::BalanceResource * balanceResource = NResource::Static::InstancePtr()->GetBalance();
	syn.max_heart = balanceResource->GetValue(pUser, EM_FRIEND_POINT_MAX);

	bool bInit = false;
	time_t initTime = NLogic::NFunction::GetRecvStaminaInitTime();
	if (initTime >= static_cast<time_t>(pUser->GetUserInfo().recv_stamina_time))
	{
		bInit = true;
		pUser->GetUserInfo().recv_stamina = 0;
	}

	pUser->GetUserInfo().recv_stamina_time = time(NULL);

	if (true == bInit)
	{
		pUser->FlushUserInfoCache();
	}

	syn.max_stamina = STAMINA_MAX_CHARGE;
	syn.cur_stamina = pUser->GetCharacterInfo().cur_stamina;

	// 친구 소식으로 받을 수 있는 체력치 (하루 MAX 24)
	syn.remain_recv_stamina = MAX_RECV_STAMINA - pUser->GetUserInfo().recv_stamina;
	syn.max_recv_stamina = MAX_RECV_STAMINA;

	::ProjectZ::NProxy::SendFriendsServer(pUser->GetUserSeq(), syn);
}

} /*NCommand*/ } /*ProjectZ*/
